package com.starblink.store.detail.view

import android.view.View
import androidx.core.os.bundleOf
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.setFragmentResult
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.starblink.android.basic.ext.click
import com.starblink.android.basic.ext.string
import com.starblink.android.basic.sensorsdata.extension.businessSuffixId
import com.starblink.android.basic.sensorsdata.extension.trackData
import com.starblink.android.basic.sensorsdata.room.entity.SkAntEntity
import com.starblink.android.basic.sensorsdata.spm.GTrackerAssistUtils
import com.starblink.android.basic.sensorsdata.spm.cfg.SpmElementDef
import com.starblink.android.basic.sensorsdata.spm.cfg.SpmPageDef
import com.starblink.android.basic.sensorsdata.spm.event.TrackEvent
import com.starblink.android.basic.sensorsdata.spm.impl.SpmTrackHandler
import com.starblink.android.basic.user.UserDataCenter
import com.starblink.android.basic.widget.dialog.BaseBottomSheetFragment
import com.starblink.basic.route.RoutePage
import com.starblink.rocketreserver.fragment.AccountF
import com.starblink.store.databinding.DialogStoreFollowStoreBinding

/**
 * 关注店铺弹窗
 */
@Route(path = RoutePage.Store.DIALOG_STORE_FOLLOW)
class StoreFollowDialog() : BaseBottomSheetFragment() {
    lateinit var viewBinding: DialogStoreFollowStoreBinding

    companion object {
        const val RESULT_FOLLOW_STORE = "RESULT_FOLLOW_STORE"
        const val KEY_RESULT = "KEY_RESULT"
    }

    @Autowired(name = RoutePage.Store.STORE_NAME)
    @JvmField
    var storeName: String = ""

    override fun getBindingRootView(): View {
        viewBinding = DialogStoreFollowStoreBinding.inflate(layoutInflater)
        return viewBinding.root
    }

    override fun initView() {
        viewBinding.btnNotNow.click {
            // 埋点：店铺主页-订阅提醒弹窗，Not Now按钮点击
            it.trackData(
                page = SpmPageDef.StoreDetailPage,
                element = SpmElementDef.Element_33083,
                params = mapOf(
                    "merchantName" to storeName,
                    "status" to if (UserDataCenter.isLogin()) "1" else "0"
                ),
                onlyHit = true
            )
            dismiss()
        }

        viewBinding.btnFollow.click {
            setFragmentResult(
                RESULT_FOLLOW_STORE,
                bundleOf(KEY_RESULT to true)
            )
            // 埋点：店铺主页-订阅提醒弹窗，Follow按钮点击
            it.trackData(
                page = SpmPageDef.StoreDetailPage,
                element = SpmElementDef.Element_33084,
                params = mapOf(
                    "merchantName" to storeName,
                    "status" to if (UserDataCenter.isLogin()) "1" else "0"
                ),
                onlyHit = true
            )
            dismiss()
        }
    }
}